<?php
require_once("../../../config.inc.php");
$isReloadable = false;
require_once("../../../app/_inc/include.php");
require_once("./_inc/layoutFunction.php");

$errMsg = "";
$layout = sxREQUEST("layout");
$band = sxREQUEST("band");

if(sxREQ("reqtype") == "save"){
	$errMsg .= layoutBandIns();
}
if(sxREQ("reqtype") == ""){
	sxRDef('band', '');
	sxRDef('description', '');
	sxRDef('display_only', 'N');
	sxRDef('flags', '');
	sxRDef('note', '');
	sxRDef('upgrade_status', 'C');
}

$aOpz = array("kMenu"=>'pro.lay', "isReloadable"=>$isReloadable);
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript">
function objFrmSubm(rt){
	document.objFrm.reqtype.value = rt;
	document.objFrm.submit();
}
</script>
  
<?php
echo(bodyHTML($aOpz));

echo getLOHeader($layout);

$aCmd = array("insMD"=>array("pag"=>"javascript:objFrmSubm('save')",
										"title"=>_t("save"),
										"text"=>_t("save")
										),
					"back"=>array()
					);
echo(commandsHTML($aCmd));	

echo getHtmlForm('objFrm');
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('reqtype','...');
echo getHtmlHidden('layout');

echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");
echo("<tr>" .
			"<td class=\"titl01\" width=\"20%\" colspan='2'>Layout Band</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Band*</td>" .
			"<td class=\"text01\">".
			getHtmlText('band',4)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Description</td>" .
			"<td class=\"text01\">".getHtmlText('description',80)."</td>" .
		"</tr>\n");
$aValDO = array('Y'=>'Yes','N'=>'No');
echo("<tr>" .
			"<td class=\"labl01\">Display only</td>" .
			"<td class=\"text01\">".getHtmlRadio('display_only',$aValDO).
		"</td>\n</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Flags</td>" .
			"<td class=\"text01\">".getHtmlText('flags',80)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Note</td>" .
			"<td class=\"text01\">".getHtmlTextArea('note',80,3)."</td>" .
		"</tr>\n");
echo("</table>");
echo("</form>");

echo(commandsHTML($aCmd));
echo(footerHTML());
exit();

function layoutBandIns(){
 	global $objSDAO;
	$errMsg = "";
	if(strlen(sxREQUEST("band")) == 0 or strlen(sxREQUEST("band")) > 4 
	or ereg("[^0-9]",sxREQUEST("band")))
		$errMsg .= "band code not numeric<br>";
	if($errMsg != ""){return $errMsg;}	
	//existence
	$sSQL = "SELECT count(*) as num FROM layout_band " .
			" WHERE layout='".$_REQUEST["layout"]."' " .
			" AND band='".$_REQUEST["band"]."'";
	$objSDAO->query($sSQL,"test");
	$row = $objSDAO->fetch("test");
	if($row["num"] != 0)
		$errMsg .= "band existing<br>";
	if($errMsg != ""){return $errMsg;}	
	$_REQUEST['band'] = str_pad($_REQUEST['band'],4,'0',STR_PAD_LEFT);
	$sSQL = "INSERT INTO " .
			"layout_band " .
			"(layout, " .
			"band, " .
			"flags, " .
			"display_only, " .
			"description, " .
			"note)" .
			"VALUES('".sxRAS("layout")."', " .
			"".sxRAS("band").", " .
			"'".sxRAS("flags")."', " .
			"'".sxRAS("display_only")."', " .
			"'".sxRAS("description")."', " .
			"'".sxRAS("note")."'" .
			")";	
	$objSDAO->exec($sSQL);
	$url = $_SESSION[USEROBJ]->getHistory(0, true);
	serverRedir($url);
	return 'abnormal end';
}
